package com.xiaoshuidi.cloud.module.member.enums.point;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;

/**
 * @description: 积分等级枚举
 * @author: neil@ixiaoshuidi.com
 * @create: 2022-12-15 10:58
 **/
public enum PointRankEnums {
    /**
     * LV1 9999积分以下
     */
    LV1("LV1", "0-9999", 1),
    /**
     * LV2 10000-19999积分
     */
    LV2("LV2", "10000-19999", 2),
    /**
     * LV3 20000-29999积分
     */
    LV3("LV3", "20000-29999", 3),
    /**
     * LV4 30000-39999积分
     */
    LV4("LV4", "30000-39999", 4),
    /**
     * LV5 40000-49999积分
     */
    LV5("LV5", "40000-49999", 5),
    /**
     * LV6 50000-59999积分
     */
    LV6("LV6", "50000-59999", 6),
    /**
     * LV7 60000积分以上
     */
    LV7("LV7", "60000-0", 7);

    private String code;
    private String points;
    private Integer rank;

    PointRankEnums(String code, String points, Integer rank) {
        this.code = code;
        this.points = points;
        this.rank = rank;
    }

    public String getCode() {
        return code;
    }

    public String getPoints() {
        return points;
    }

    public Integer getRank() {
        return rank;
    }

    public static PointRankEnums getInstance(Long point) {
        for (PointRankEnums lvEnum : values()) {
            String[] points = lvEnum.points.split("-");
            if (point >= Long.valueOf(points[0]) && (point <= Long.valueOf(points[1]) || "0".equals(points[1]))) {
                return lvEnum;
            }
        }
        return null;
    }

    public static List<HashMap<String,Object>> getList() {
        List<HashMap<String, Object>> list = new ArrayList<>();
        for (PointRankEnums enums : EnumSet.allOf(PointRankEnums.class)) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("code",enums.code);
            map.put("points",enums.points);
            map.put("rank",enums.rank);
            list.add(map);
        }
        return list;
    }

}
